﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ReportBase.cs" company="Collaboris Ltd.">
//   Copyright (c) Collaboris Ltd. All rights Reserved.
// </copyright>
// <summary>
//   Defines the ReportBase type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Collaboris.Saf.Engine.Report
{
    using System;
    using System.Collections.Generic;
    using System.Xml.Serialization;

    [Serializable]
    public class ReportBase<T> : IProgressReport
    {
        #region Fields (8) 

        private string assemblyName;
        private DateTime endDateTime;
        private ProcessMode mode;
        private string name;
        private DateTime startDateTime;
        private ProcessStatus status;
        private string typeName;
        private Guid id;

        #endregion Fields 

        #region Properties (9) 

        /// <summary>
        /// Signifies which Mode was ran on the Action
        /// in the macro.
        /// </summary>
        [XmlAttribute]
        public ProcessMode Mode
        {
            get
            {
                return this.mode;
            }
            set
            {
                this.mode = value;
            }
        }

        /// <summary>
        /// The AssemblyName that contains the Action.
        /// </summary>
        [XmlAttribute]
        public string AssemblyName
        {
            get
            {
                return this.assemblyName;
            }

            set
            {
                this.assemblyName = value;
            }
        }

        /// <summary>
        /// The Date and Time that the Action finished
        /// processing.
        /// </summary>
        [XmlAttribute]
        public DateTime EndDateTime
        {
            get
            {
                return this.endDateTime;
            }
            set
            {
                this.endDateTime = value;
            }
        }

        /// <summary>
        /// The name of the IAction. 
        /// </summary>
        [XmlAttribute]
        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        /// <summary>
        /// The Date and Time that the Action started
        /// processing.
        /// </summary>
        [XmlAttribute]
        public DateTime StartDateTime
        {
            get
            {
                return this.startDateTime;
            }
            set
            {
                this.startDateTime = value;
            }
        }

        /// <summary>
        /// Gets or Sets the status (outcome) of the IAction in the Macro.
        /// </summary>
        /// <value>The status.</value>
        [XmlAttribute]
        public virtual ProcessStatus Status
        {
            get
            {
                return this.status;
            }

            set
            {
                this.status = value;
            }
        }

        /// <summary>
        /// String Representation of the Namespace
        /// and type for the executing Action.
        /// </summary>
        [XmlAttribute]
        public string TypeName
        {
            get
            {
                return this.typeName;
            }
            set
            {
                this.typeName = value;
            }
        }

        public Guid Id
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        #endregion Properties 
        
        /// <summary>
        /// List of MacroReports 
        /// </summary>
        [XmlElement]
        protected List<T> reportList = new List<T>();
      

        //public IList<IProgressReport> AllReports
        //{
        //    get
        //    {
        //        List<IProgressReport> fullList = new List<IProgressReport>();
        //        GetAllReports(fullList, this);
        //        return fullList;
        //    }
        //}

        //private void GetAllReports(List<IProgressReport> fullList, T rootReport)
        //{
        //    foreach (IProgressReport macroReport in rootReport.Reports)
        //    {
        //        fullList.Add(macroReport);
        //        if (macroReport is MacroReport)
        //            GetAllReports(fullList, ((MacroReport)macroReport));
        //    }
        //    return;
        //}


        /// <summary>
        /// Determines if the new <see cref="ProcessStatus"/> is higher
        /// than the current <see cref="ProcessStatus"/>.
        /// </summary>
        /// <param name="newStatus"></param>
        /// <param name="currentStatus"></param>
        /// <returns></returns>
        protected ProcessStatus DetermineWorstCase(ProcessStatus newStatus, ProcessStatus currentStatus)
        {
            if (newStatus > currentStatus)
                return newStatus;
            else
                return currentStatus;
        }

        /// <summary>
        /// Use the name of the Report in the ToString()
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.Name;
        }
    }
}